package com.cqupt.scanning.system.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cqupt.scanning.system.admin.entity.DeviceThree;
import com.cqupt.scanning.system.admin.service.DeviceThreeService;
import com.cqupt.scanning.system.utils.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Data: 2021/7/8 16:51
 * @Author: 宋宝梁
 */
@RestController
@RequestMapping("/admin/organization/dev/three")
public class DeviceThreeController {


    private DeviceThreeService deviceThreeService;

    @Autowired
    public DeviceThreeController(DeviceThreeService deviceThreeService) {
        this.deviceThreeService = deviceThreeService;
    }

    /**
     * 通过设备id逻辑删除设备(同时删除绑定账号)
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{devId}")
    @PreAuthorize("hasAuthority('3Dscanning.delete')")
    public R delById(@PathVariable("devId") Integer id) {
        return deviceThreeService.delById(id);
    }

    /**
     * 获取所有三维扫描设备（支持设备编码模糊查询）
     * @param query
     * @param current
     * @param size
     * @return
     */
    @GetMapping("/getAll")
    @PreAuthorize("hasAuthority('3Dscanning.getAll')")
    public R getAll(@RequestParam("query") String query,
                    @RequestParam(value = "pageNum", defaultValue = "1") Integer current,
                    @RequestParam(value = "pageSize", defaultValue = "10") Integer size) {
        Page<DeviceThree> page = new Page<>(current, size);
        return deviceThreeService.getAll(page, query);
    }
}
